//
//  XJchucaiViewController.m
//  gangquOASystem
//
//  Created by michael on 2018/7/25.
//  Copyright © 2018年 czd. All rights reserved.
//

#import "XJchucaiViewController.h"

@interface XJchucaiViewController ()

@end

@implementation XJchucaiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"嘉兴港区机关工作人员出差审批单";
        self.view.backgroundColor = [UIColor whiteColor];
//19
    // Do any additional setup after loading the view.
    [self initview];
}
- (void)initview{
if(!_tableView){
 _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth,KScreenHeight-kTopHeight) style:UITableViewStylePlain];
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.bounces = NO;
_tableView.dataSource = self;
_tableView.delegate = self;
    self.tableView.backgroundColor = [UIColor whiteColor];

[self.view addSubview:_tableView];

}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 9;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row ==3||indexPath.row ==4||indexPath.row ==5) {
    return 140;
}
else{
    return 60;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.row ==0){

static NSString *cellid00 = @"cellid00";
    newTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid00];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[newTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid00];
    }
    cell.seltag = 100+indexPath.row;
    cell.string = @"工作部门";
//    cell.dic = _indexPathdowm[indexPath.row];
        return cell;

}else if(indexPath.row ==1){

static NSString *cellid01 = @"cellid01";
    newTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid01];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[newTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid01];
    }
    cell.seltag = 100+indexPath.row;
    cell.string = @"出差人";
//    cell.dic = _indexPathdowm[indexPath.row];
        return cell;

}else if(indexPath.row ==2){

static NSString *cellid02 = @"cellid02";
    newTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid02];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[newTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid02];
    }
    cell.seltag = 100+indexPath.row;
    cell.string = @"出差事由";
//    cell.dic = _indexPathdowm[indexPath.row];
        return cell;

}else if(indexPath.row ==3){

static NSString *cellid04 = @"cellid04";
    chucaiTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid04];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[chucaiTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid04];
    }
    cell.seltag = indexPath.row;
     [cell.timebutton1 addTarget:self action:@selector(timeaction1:) forControlEvents:UIControlEventTouchUpInside];
     [cell.timebutton2 addTarget:self action:@selector(timeaction2:) forControlEvents:UIControlEventTouchUpInside];

//    cell.string = @"出差事由";
//    cell.dic = _indexPathdowm[indexPath.row];
        return cell;

}else if(indexPath.row ==4){

static NSString *cellid05 = @"cellid05";
    chucaiTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid05];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[chucaiTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid05];
    }
    cell.seltag = indexPath.row;
     [cell.timebutton1 addTarget:self action:@selector(timeaction1:) forControlEvents:UIControlEventTouchUpInside];
     [cell.timebutton2 addTarget:self action:@selector(timeaction2:) forControlEvents:UIControlEventTouchUpInside];

//    cell.string = @"出差事由";
//    cell.dic = _indexPathdowm[indexPath.row];
        return cell;

}else if(indexPath.row ==5){

static NSString *cellid06 = @"cellid06";
    chucaiTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid06];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[chucaiTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid06];
    }
    cell.seltag = indexPath.row;
     [cell.timebutton1 addTarget:self action:@selector(timeaction1:) forControlEvents:UIControlEventTouchUpInside];
     [cell.timebutton2 addTarget:self action:@selector(timeaction2:) forControlEvents:UIControlEventTouchUpInside];

//    cell.string = @"出差事由";
//    cell.dic = _indexPathdowm[indexPath.row];
        return cell;

}else if(indexPath.row ==6){

static NSString *cellid07 = @"cellid07";
    newTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid07];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[newTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid07];
    }
    cell.seltag = 100+indexPath.row;
    cell.string = @"人均经费(元)";
//    cell.dic = _indexPathdowm[indexPath.row];
        return cell;

}else if(indexPath.row ==7){

static NSString *cellid08 = @"cellid08";
    newTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid08];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[newTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid08];
    }
    cell.seltag = 100+indexPath.row;
    cell.string = @"列支渠道";
//    cell.dic = _indexPathdowm[indexPath.row];
        return cell;

}
else{
     static NSString *CellIdentifier2 = @"Cellbendititlepic2";

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

//        cell.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];
    }
     UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
      button.frame = CGRectMake(20, 10, (KScreenWidth-60)/2, 40);
button.backgroundColor = [UIColor colorWithHexString:@"0a62ea"];

    [button setTitle:@"保存" forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize: 15.0];
    [button setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
        button.layer.cornerRadius = button.height/2;
        [button addTarget:self action:@selector(baocunaction) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:button];

     UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
      button2.frame = CGRectMake(button.right+ 20, 10, (KScreenWidth-60)/2, 40);
button2.backgroundColor = [UIColor colorWithHexString:@"0a62ea"];

    [button2 setTitle:@"发送" forState:UIControlStateNormal];
    button2.titleLabel.font = [UIFont systemFontOfSize: 15.0];
    [button2 setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
        button2.layer.cornerRadius = button.height/2;
        [button2 addTarget:self action:@selector(fasongaction) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:button2];
    return cell;
    
  
    }
}
- (void)timeaction1:(UIButton *)btn{
        [self.view endEditing:YES];

_timePicker1 = [[MHDatePicker alloc] init];
    _timePicker1.isBeforeTime = YES;
    _timePicker1.datePickerMode = UIDatePickerModeDate;
    zhucebutton *button = (zhucebutton *)[self.view viewWithTag:(btn.tag)];
    __weak typeof(self) weakSelf = self;
[_timePicker1 didFinishSelectedDate:^(NSDate *selectedDate) {
//        NSString *string = [NSString stringWithFormat:@"%@",[NSDate dateWithTimeInterval:3600*8 sinceDate:selectedDate]];
//        weakSelf.myLabel2.text = string;
      NSString *string = [weakSelf dateStringWithDate:selectedDate DateFormat:@"yyyy-MM-dd"];
            [button setTitle:string forState:UIControlStateNormal];

      if (btn.tag ==303) {
       weakSelf.beforetime1 = string;
      }
       if (btn.tag ==304) {
       weakSelf.beforetime2 = string;
      }
       if (btn.tag ==305) {
       weakSelf.beforetime3 = string;
      }
    
    }];
}

- (void)timeaction2:(UIButton *)btn{
        [self.view endEditing:YES];

_timePicker2 = [[MHDatePicker alloc] init];
    _timePicker2.isBeforeTime = YES;
    _timePicker2.datePickerMode = UIDatePickerModeDate;
    zhucebutton *button = (zhucebutton *)[self.view viewWithTag:(btn.tag)];
    __weak typeof(self) weakSelf = self;
[_timePicker2 didFinishSelectedDate:^(NSDate *selectedDate) {
//        NSString *string = [NSString stringWithFormat:@"%@",[NSDate dateWithTimeInterval:3600*8 sinceDate:selectedDate]];
//        weakSelf.myLabel2.text = string;
      NSString *string = [weakSelf dateStringWithDate:selectedDate DateFormat:@"yyyy-MM-dd"];
            [button setTitle:string forState:UIControlStateNormal];

      if (btn.tag ==403) {
       weakSelf.aftertime1 = string;
      }
       if (btn.tag ==404) {
       weakSelf.aftertime2 = string;
      }
       if (btn.tag ==405) {
       weakSelf.aftertime3 = string;
      }
    
    }];
}
- (NSString *)dateStringWithDate:(NSDate *)date DateFormat:(NSString *)dateFormat
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:dateFormat];
    [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"]];
    NSString *str = [dateFormatter stringFromDate:date];
    return str ? str : @"";
}
- (void)baocunaction{
zhucetextfield *bumenview = (zhucetextfield *)[self.view viewWithTag:100];//工作部门
zhucetextfield *personview = (zhucetextfield *)[self.view viewWithTag:101];//出差人
zhucetextfield *reasonview = (zhucetextfield *)[self.view viewWithTag:102];//出差事由
// 3 4 5
_beforetime1,_aftertime1; //
zhucetextfield *startplaceview1 = (zhucetextfield *)[self.view viewWithTag:103];//出差地点
zhucetextfield *endplaceview1 = (zhucetextfield *)[self.view viewWithTag:203];//出差地点

_beforetime2,_aftertime2; //
zhucetextfield *startplaceview2 = (zhucetextfield *)[self.view viewWithTag:104];//出差地点
zhucetextfield *endplaceview2 = (zhucetextfield *)[self.view viewWithTag:204];//出差地点

_beforetime3,_aftertime3; //
zhucetextfield *startplaceview3 = (zhucetextfield *)[self.view viewWithTag:105];//出差地点
zhucetextfield *endplaceview3 = (zhucetextfield *)[self.view viewWithTag:205];//出差地点


zhucetextfield *jingfeiview = (zhucetextfield *)[self.view viewWithTag:106];//人均经费(元)
zhucetextfield *qudaoview = (zhucetextfield *)[self.view viewWithTag:107];//列支渠道

NSString *json =[NSString stringWithFormat: @"{'department':'%@','person':'%@','reason':'%@', 'starttime1':'%@','endtime1':'%@','startplace1':'%@','endplace1':'%@','starttime2':'%@','endtime2':'%@','startplace2':'%@','endplace3':'%@','starttime3':'%@','endtime3':'%@','startplace2':'%@','endplace3':'%@','funds':'%@','channel':'%@'}",bumenview.text,personview.text,reasonview.text,_beforetime1,_aftertime1,startplaceview1.text,endplaceview1.text,_beforetime2,_aftertime2,startplaceview2.text,endplaceview2.text,_beforetime3,_aftertime3,startplaceview3.text,endplaceview3.text,jingfeiview.text,qudaoview.text];







}
- (void)fasongaction{


}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
